package com.sc.nft.admin.controller;


import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.*;
import com.sc.nft.service.SupplierManageService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 供应商管理(SupplierManage)表控制层
 *
 * @author 王伟成
 * @since 2023-10-17 15:55:29
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/supplierManage")
@Api(tags = "供应商管理")
@Valid
public class SupplierManageController {
    /**
     * 服务对象
     */
    private final SupplierManageService supplierManageService;



    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增", notes = "新增", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result save(@RequestBody SupplierManageSaveDTO supplierManageSaveDTO) {
        supplierManageService.save(supplierManageSaveDTO);
        return Result.success();
    }

    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "编辑", notes = "编辑", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result edit(@RequestBody SupplierManageEditDTO supplierManageEditDTO) {
        supplierManageService.edit(supplierManageEditDTO);
        return Result.success();
    }

    @PostMapping(value = "/binding", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "绑定", notes = "绑定", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result binding(@RequestBody SupplierManageBindingDTO supplierManageBindingDTO) {
        supplierManageService.binding(supplierManageBindingDTO);
        return Result.success();
    }

    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分页", notes = "分页", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<SupplierManagePageVO> page(@RequestBody SupplierManagePageDTO supplierManagePageDTO) {
        return PageResult.success(supplierManageService.page(supplierManagePageDTO));
    }

    @PostMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取单条", notes = "获取单条", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<SupplierManagePageVO> getById(@RequestBody IdRequest idRequest) {
        return Result.success(supplierManageService.getById(idRequest.getId()));
    }

    @PostMapping(value = "/removeById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除单条", notes = "删除单条", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result removeById(@RequestBody IdRequest idRequest) {
        supplierManageService.removeById(idRequest.getId());
        return Result.success();
    }

    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<SupplierManagePageVO>> list() {
        return Result.success(supplierManageService.list());
    }


}
